package com.xhcl.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xhcl.common.annotation.Log;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.system.domain.TGgXmxx;
import com.xhcl.system.service.ITGgXmxxService;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.common.core.domain.Stree;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.common.utils.StringUtils;
import com.xhcl.common.core.domain.Ztree;
import com.xhcl.common.core.page.TableDataInfo;

/**
 * 项目信息Controller
 * 
 * @author xhcl
 * @date 2020-11-01
 */
@Controller
@RequestMapping("/system/xmxx")
public class TGgXmxxController extends BaseController
{
    private String prefix = "system/xmxx";

    @Autowired
    private ITGgXmxxService tGgXmxxService;

    @RequiresPermissions("system:xmxx:view")
    @GetMapping()
    public String xmxx()
    {
        return prefix + "/xmxx";
    }

    /**
     * 查询项目信息树列表
     */
    @RequiresPermissions("system:xmxx:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGgXmxx tGgXmxx)
    {
    	startPage();
    	List<TGgXmxx> list = tGgXmxxService.selectTGgXmxxList(tGgXmxx);
    	return getDataTable(list);
    }

    /**
     * 导出项目信息列表
     */
    @RequiresPermissions("system:xmxx:export")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGgXmxx tGgXmxx)
    {
        List<TGgXmxx> list = tGgXmxxService.selectTGgXmxxList(tGgXmxx);
        ExcelUtil<TGgXmxx> util = new ExcelUtil<TGgXmxx>(TGgXmxx.class);
        return util.exportExcel(list, "xmxx");
    }

    /**
     * 新增项目信息
     */
    @GetMapping(value = { "/add/{xmbm}", "/add/" })
    public String add(@PathVariable(value = "xmbm", required = false) String xmbm, ModelMap mmap)
    {
        if (StringUtils.isNotNull(xmbm))
        {
            mmap.put("tGgXmxx", tGgXmxxService.selectTGgXmxxById(xmbm));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存项目信息
     */
    @RequiresPermissions("system:xmxx:add")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGgXmxx tGgXmxx)
    {
        return toAjax(tGgXmxxService.insertTGgXmxx(tGgXmxx));
    }

    /**
     * 修改项目信息
     */
    @GetMapping("/edit/{xmbm}")
    public String edit(@PathVariable("xmbm") String xmbm, ModelMap mmap)
    {
        TGgXmxx tGgXmxx = tGgXmxxService.selectTGgXmxxById(xmbm);
        mmap.put("tGgXmxx", tGgXmxx);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目信息
     */
    @RequiresPermissions("system:xmxx:edit")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGgXmxx tGgXmxx)
    {
        return toAjax(tGgXmxxService.updateTGgXmxx(tGgXmxx));
    }

    /**
     * 删除
     */
    @RequiresPermissions("system:xmxx:remove")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{xmbm}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("xmbm") String xmbm)
    {
        return toAjax(tGgXmxxService.deleteTGgXmxxById(xmbm));
    }

    /**
     * 选择项目信息树
     */
    @GetMapping(value = { "/selectXmxxTree/{dwbm}", "/selectXmxxTree/" })
    public String selectXmxxTree(@PathVariable(value = "dwbm", required = false) String dwbm, ModelMap mmap)
    {
        /*if (StringUtils.isNotNull(xmbm))
        {
            mmap.put("tGgXmxx", tGgXmxxService.selectTGgXmxxById(xmbm));
        }*/
        if (StringUtils.isNotNull(dwbm))
        {
        	 mmap.put("dwbm", dwbm);
        }
        return prefix + "/tree";
    }

    /**
     * 加载项目信息树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Stree> treeData(String dwbm)
    {
        List<Stree> ztrees = tGgXmxxService.selectTGgXmxxTree(dwbm);
        return ztrees;
    }
}
